<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.getForms.php');

$aForms = getForms();

if (!isset($aForms[reqVar('cod')])) {
	backOnErr("formView - manca cod");
	exit();
}
$aFormX = $aForms[reqVar('cod')];

$sql_sel = "SELECT c.*" .
		" FROM ovf_campi_form c " .
		" WHERE c.cod_form = '".reqvar('cod')."'".
		" ORDER BY c.riga,c.posiz ";
$objDB->query($sql_sel,'selRecCampi');
//dbg_($sql_sel);
$cmdL1 = "";
$cmdR1 = "";
$cmdR1 .= cmdTorna(); 

$cmdL = "";

$cmdR = "";
if (true) {
	$cmdR .= "&nbsp;&nbsp;&nbsp;";
	$cmdR .= "<a class=\"cmd1\" href=\"formCamIns.php?cod=".reqVar('cod')."&$sXSNQS\">nuovo campo</a>"; 
}

testaHtml('Gestione form', 'Form',$msgPag, 'gest');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL1?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR1?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="lab1" width='20%' align='left'>Form</td>
      <td class="txt1" width='20%' align='left'>
			<span style='font-family:lucida console,courier;'><?=reqVar('cod')?></span>
		</td>
      <td class="txt1" width='60%' align='left'>
			<?=$aFormX['descr']?>
		</td>
   </tr>
   <tr>
      <td class="lab1" valign='top'>File</td>
      <td class="txt1" colspan='2' align='left'>     	
			<?
			foreach($aFormX['files'] as $nomeX => $aX) {
				echo "<a href='../file/fileView.php?cod=$nomeX&$sXSNQS' class='txt1'>";
				echo $aX['alias']." - ".$nomeX."</a><br/>";
			}	
			?>
		</td>
   </tr>
			<?
if (!empty($aFormX['nota'])) {
?>
   <tr>
      <td class="lab1" valign='top'>Nota</td>
      <td class="txt1" colspan='2' align='left'>
			<?=getHtmlViewNote($aFormX['nota'])?>
		</td>
   </tr>
<?
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR."&nbsp;&nbsp;&nbsp;".$cmdR1?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="lab1" align='center' colspan='1'>&nbsp;</td>
      <td class="lab1" align='center' colspan='20'>campi</td>
   </tr>
	<tr>
		<td class="lab1" align='center' colspan='1'>Riga</td>
<?php
	for($k=1; $k<=20; $k++) {
		echo "<td width='5%' class='lab1' align='center'>$k</td>";
	}
?>
	</tr>
         <?php 
$acX = $objDB->fetch('selRecCampi');
while($acX) {
	$riga = $acX['riga'];
	echo "<tr>\n";
	echo "<td class='lab1' colspan='1' align='right'>$riga&nbsp;</td>\n";
	$colDisp = 20;
	while($acX && $riga == $acX['riga']) {
		if ($colDisp > 0) {
			$sHref = "formCamMod.php?cod=".reqVar('cod')."&r=".$acX['riga']."&p=".$acX['posiz']."&xsn=".XSN;
			if ($acX['label_size']>0) {
				$cols = ($acX['label_size']<$colDisp)?$acX['label_size']:$colDisp;
				echo "<td class='lab1' colspan='$cols'>"
					."<a href='$sHref' class='lab1'>".$acX['label']."</a></td>\n";
				$colDisp -= $cols;
			}
			if ($acX['campo_size']>0) {
				$cols = ($acX['campo_size']<$colDisp)?$acX['campo_size']:$colDisp;
				echo "<td class='txt1' colspan='$cols'>"
					."<a href='$sHref' class='txt1'>".$acX['posiz'].")&nbsp;".$acX['campo']."</a></td>\n";
				$colDisp -= $cols;
			}
		}
		$acX = $objDB->fetch('selRecCampi');
	} 
	if ($colDisp>0) {
		echo "<td class='txt1' colspan='$colDisp'>&nbsp;</td>\n";
	}
	echo "</tr>\n";
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR."&nbsp;&nbsp;&nbsp;".$cmdR1?>
      </td>
   </tr>
</table>
         <?
echo "</form>\n";
codaHtml();
exit();
